libxl: pass libxl__spawn_starting to libxl__spawn_spawn.
authorIan Campbell <ian.campbell@citrix.com>
Tue, 24 May 2011 14:21:26 +0000 (15:21 +0100)
committerIan Campbell <ian.campbell@citrix.com>
Tue, 24 May 2011 14:21:26 +0000 (15:21 +0100)
Passing a libxl__device_model_starting to a generic function and expecting it
to scrobble inside for the generic data structure is a strange interface.
Instead pass in a libxl__spawn_starting and an opaque hook data pointer.

The for_spawn member of libxl__device_model_starting was annotated with
"first!", suggesting that someone intended to use pointer casting tricks to
move between the outer and inner struct. However the field is a pointer not a
inline struct so this doesn't work (and it isn't used this way anyhow). Remove
the comment, and move the field away from the front for good measure.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/libxl/libxl_dm.c
tools/libxl/libxl_exec.c
tools/libxl/libxl_internal.h

index 58648bdfac4d9a684c37c9b379732755f7655f78..a71d7cfcbe25a31ab5a83b1e84cd58fed5d9e778 100644 (file)
@@ -825,7 +825,8 @@ retry_transaction:
         }
     }
 
-    rc = libxl__spawn_spawn(gc, p, "device model", dm_xenstore_record_pid);
+    rc = libxl__spawn_spawn(gc, p->for_spawn, "device model",
+                            dm_xenstore_record_pid, p);
     if (rc < 0)
         goto out_close;
     if (!rc) { /* inner child */
index a72cb83bee34dcb426d4808a414bb1cf1ba021e2..70b54259a6e55147f78134712943b84e6786703d 100644 (file)
@@ -92,16 +92,16 @@ void libxl_report_child_exitstatus(libxl_ctx *ctx,
 }
 
 int libxl__spawn_spawn(libxl__gc *gc,
-                      libxl__device_model_starting *starting,
+                      libxl__spawn_starting *for_spawn,
                       const char *what,
                       void (*intermediate_hook)(void *for_spawn,
-                                                pid_t innerchild))
+                                                pid_t innerchild),
+                      void *hook_data)
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
     pid_t child, got;
     int status;
     pid_t intermediate;
-    libxl__spawn_starting *for_spawn = starting->for_spawn;
 
     if (for_spawn) {
         for_spawn->what = strdup(what);
@@ -127,7 +127,7 @@ int libxl__spawn_spawn(libxl__gc *gc,
     if (!child)
         return 0; /* caller runs child code */
 
-    intermediate_hook(starting, child);
+    intermediate_hook(hook_data, child);
 
     if (!for_spawn) _exit(0); /* just detach then */
 
index 64e1d56459191e53e1ec3a178f79b7e5da1e1951..9c77f44740f82e378db72bf19eff5628b1841cce 100644 (file)
@@ -237,9 +237,9 @@ typedef struct {
 } libxl__spawn_starting;
 
 typedef struct {
-    libxl__spawn_starting *for_spawn; /* first! */
     char *dom_path; /* from libxl_malloc, only for dm_xenstore_record_pid */
     int domid;
+    libxl__spawn_starting *for_spawn;
 } libxl__device_model_starting;
 
 /* from xl_create */
@@ -277,9 +277,10 @@ _hidden int libxl__wait_for_device_model(libxl__gc *gc,
                                 void *check_callback_userdata);
 
 _hidden int libxl__spawn_spawn(libxl__gc *gc,
-                      libxl__device_model_starting *starting,
+                      libxl__spawn_starting *starting,
                       const char *what,
-                      void (*intermediate_hook)(void *for_spawn, pid_t innerchild));
+                      void (*intermediate_hook)(void *for_spawn, pid_t innerchild),
+                      void *hook_data);
 _hidden int libxl__destroy_device_model(libxl__gc *gc, uint32_t domid);
 
   /* Logs errors.  A copy of "what" is taken.  Return values: